package com.example.twoscroolview.activity

import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import androidx.viewpager2.adapter.FragmentStateAdapter
import com.example.twoscroolview.R
import com.example.twoscroolview.adapter.StringAdapter
import com.example.twoscroolview.fragment.Fragment1
import com.google.android.material.tabs.TabLayoutMediator
import kotlinx.android.synthetic.main.activity_two_scroll.*

/**
 * 悬浮 scrool嵌套recycleview 冲突
 */
class TwoScrollViewActivity :AppCompatActivity(){
    val list = mutableListOf<String>()

    private val adapter by lazy {
        StringAdapter()
    }

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_two_scroll)
        initView()
    }

    private fun initView() {
      val tabs =   listOf<String>("111","222","333","4444")
        for (i in 0..7){
            list.add("TwoScrollViewActivity------"+i)
        }
        viewpage2.adapter = object :FragmentStateAdapter(this){
            override fun getItemCount(): Int {
                return 4
            }

            override fun createFragment(position: Int): Fragment {
                return Fragment1()
            }

        }
        TabLayoutMediator(tablayout,viewpage2) { tab, position ->
            tab.setText(tabs[position])
        }.attach()
        adapter.addData(list)
        recycleView1.layoutManager=GridLayoutManager(this,4)
        recycleView1.adapter = adapter


    }
}